package com.jhhc.StormSurgeForecast.StormSurge.Uitl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;


import com.jhhc.StormSurgeForecast.StormSurge.Pojo.BdmsFbcTf;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BDMS_FBC_TF;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BdmsFbcTfpathF;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BdmsFbcTfpathR;
import com.jhhc.StormSurgeForecast.StormSurge.Service.BdmsFbcTfService;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import com.jhhc.StormSurgeForecast.StormSurge.Service.BdmsFbcTfpathFService;
import com.jhhc.StormSurgeForecast.StormSurge.Service.BdmsFbcTfpathRService;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Administrator
 */

@Service
public class TyphoonUtil {

    @Autowired
    private BdmsFbcTfpathFService bdmsFbcTfpathFService;
    @Autowired
    private BdmsFbcTfpathRService bdmsFbcTfpathRService;
    @Autowired
    private BdmsFbcTfService bdmsFbcTfService;
    //解析上海台风
    //urlhttps://sjkf.swj.sh.gov.cn:9443//service/api/swic/getDangQianTaiFeng?client_id=55690ecb85a444ae9cf259dd9ee81886&access_token=8e698393435b45dc90f0cca8c5f002cd

     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
      Calendar calendar = new GregorianCalendar();

    public  String replaceDirection(String direction) {
        direction = direction.replaceAll("N", "北");
        direction = direction.replaceAll("W", "西");
        direction = direction.replaceAll("S", "南");
        direction = direction.replaceAll("E", "东");
        return direction;
    }
    public  Integer insertTFInfo() throws URISyntaxException, IOException, ParseException {
        List<BdmsFbcTf> bdmsFbcTfs = new ArrayList<>();
        List<BdmsFbcTfpathR> bdmsFbcTfpathRS = new ArrayList<>();
        //获取当前台风信息
        String  url= "http://31.16.14.216:9090/service/api/swic/getDangQianTaiFeng";
        //创建Http请求
        CloseableHttpClient httpClient = HttpClients.createDefault();
        // 设置URI
        URIBuilder builder = new URIBuilder(url);
        builder.setParameter("client_id", "55690ecb85a444ae9cf259dd9ee81886");
        builder.setParameter("access_token", "8e698393435b45dc90f0cca8c5f002cd");

        URI uri = builder.build();
        //创建Get请求
        HttpGet httpGet = new HttpGet(uri);
        httpGet.addHeader("Content-Type", "application/json; charset=utf-8");
        // 发送请求并获取响应
        CloseableHttpResponse response = httpClient.execute(httpGet);//
        // 处理响应
        String responseBody = EntityUtils.toString(response.getEntity());
        // 使用Fastjson解析JSON字符串
        JSONArray jsonArray = JSONArray.parseArray(responseBody);

        // 遍历JSONArray并获取每个JSONObject
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            // 获取"WIND_NAME"字段的值
            String windName = jsonObject.getString("WIND_NAME");
            String formattedWindName = windName.replaceAll("[^0-9]", "");
            String tfid ="20"+formattedWindName;
            //台风基础信息入库
            BdmsFbcTf  bdmsFbcTf = new BdmsFbcTf();
            bdmsFbcTf.setTfid(tfid);
            String tfnm = windName.replaceAll("\\d", "");
            bdmsFbcTf.setTfnameC(tfnm);
            bdmsFbcTf.setStartyear(Integer.valueOf(tfid.substring(0,4)));
            bdmsFbcTfs.add(bdmsFbcTf);
            //获取到WIND_NAME后 去获取预报路径
            String urlData = "http://31.16.14.216:9090/service/api/swic/getTaiFengLuJing";
            CloseableHttpClient httpClientData = HttpClients.createDefault();
            // 设置URI
            URIBuilder builderData = new URIBuilder(urlData);
            builderData.setParameter("client_id", "55690ecb85a444ae9cf259dd9ee81886");
            builderData.setParameter("access_token", "8e698393435b45dc90f0cca8c5f002cd");
            builderData.addParameter("WIND_NAME",windName);
            URI uriData = builderData.build();
            //创建Get请求
            HttpGet httpGetData = new HttpGet(uriData);
            httpGetData.addHeader("Content-Type", "application/json; charset=utf-8");
            // 发送请求并获取响应
            CloseableHttpResponse responseData= httpClientData.execute(httpGetData);//
            // 处理响应
            String responseBodyData = EntityUtils.toString(responseData.getEntity());
            // 使用Fastjson解析JSON字符串
            JSONArray jsonArrayData = JSONArray.parseArray(responseBodyData);
            for (int k = 0; k < jsonArrayData.size(); k++) {
                JSONObject jsonObjectData = jsonArrayData.getJSONObject(k);
               // System.out.println("解析的数据========="+jsonObjectData);
                //先解析实测路径
                BdmsFbcTfpathR bdms_fbc_tfpath_r =new BdmsFbcTfpathR();

                bdms_fbc_tfpath_r.setTfid(tfid);
                bdms_fbc_tfpath_r.setJd(jsonObjectData.getDouble("LON"));
                //解析字符串
                //MOVE_DIRECTION
                String MOVE_DIRECTION = jsonObjectData.getString("MOVE_DIRECTION");
                if (MOVE_DIRECTION!=null){
                    String replacedDirection = replaceDirection(MOVE_DIRECTION);
                    bdms_fbc_tfpath_r.setMoveway(replacedDirection);
                }
                //bdms_fbc_tfpath_r.setPower(jsonObjectData.getInteger("WIND_SPEED"));
                bdms_fbc_tfpath_r.setWd(jsonObjectData.getDouble("LAT"));
                bdms_fbc_tfpath_r.setMovespeed(jsonObjectData.getInteger("MOVE_SPEED"));
                bdms_fbc_tfpath_r.setYmdhm(jsonObjectData.getString("WIND_TIME"));
                bdms_fbc_tfpath_r.setPressure(jsonObjectData.getInteger("AIR_PRESSURE"));
                bdms_fbc_tfpath_r.setRadius7(jsonObjectData.getInteger("SEVEN_WIND"));
                bdms_fbc_tfpath_r.setRadius10(jsonObjectData.getInteger("TEN_WIND"));
                System.out.println("实测:"+bdms_fbc_tfpath_r);
                bdmsFbcTfpathRS.add(bdms_fbc_tfpath_r);
                // 获取所有预报机构的数据

                //创建接收集合
                List<BdmsFbcTfpathF> bdms_fbc_tfpath_fs = new ArrayList<>();
                for (String key : jsonObjectData.keySet()) {
                    String dept = key.substring(0, 3);
                    switch (dept) {
                        case "BJ_":
                            Integer hour = Integer.valueOf(key.replaceAll("[^0-9]", ""));
                            BdmsFbcTfpathF bdms_fbc_tfpath_f = new BdmsFbcTfpathF();
                            bdms_fbc_tfpath_f.setTfid(bdms_fbc_tfpath_r.getTfid());
                            bdms_fbc_tfpath_f.setUserId(0);
                            bdms_fbc_tfpath_f.setPid(0);
                            bdms_fbc_tfpath_f.setReportDept("中国");
                            bdms_fbc_tfpath_f.setRealTm(bdms_fbc_tfpath_r.getYmdhm());
                            calendar.setTime(format.parse(bdms_fbc_tfpath_r.getYmdhm()));
                            switch (hour) {
                                case 6:
                                    calendar.add(Calendar.HOUR, 6);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_6"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_6"));
                                    break;
                                case 12:
                                calendar.add(Calendar.HOUR, 12);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_12"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_12"));
                                break;
                                case 24:
                                    calendar.add(Calendar.HOUR, 24);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_24"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_24"));
                                    break;
                                case 36:
                                    calendar.add(Calendar.HOUR, 36);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_36"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_36"));
                                    break;
                                case 48:
                                    calendar.add(Calendar.HOUR, 48);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_48"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_48"));
                                    break;
                                case 60:
                                    calendar.add(Calendar.HOUR, 60);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_60"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_60"));
                                case 72:
                                    calendar.add(Calendar.HOUR, 72);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_72"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_72"));
                                    break;
                                case 96:
                                    calendar.add(Calendar.HOUR, 96);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_96"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_96"));
                                    break;
                                case 120:
                                    calendar.add(Calendar.HOUR, 120);
                                    bdms_fbc_tfpath_f.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f.setJd(jsonObjectData.getDouble("BJ_LON_120"));
                                    bdms_fbc_tfpath_f.setWd(jsonObjectData.getDouble("BJ_LAT_120"));
                                    break;
                                default:
                                    break;
                            }
                            bdms_fbc_tfpath_fs.add(bdms_fbc_tfpath_f);
                            break;
                        case "HK_":
                            Integer hourHK = Integer.valueOf(key.replaceAll("[^0-9]", ""));
                            BdmsFbcTfpathF bdms_fbc_tfpath_f_HK = new BdmsFbcTfpathF();
                            bdms_fbc_tfpath_f_HK.setTfid(bdms_fbc_tfpath_r.getTfid());
                            bdms_fbc_tfpath_f_HK.setUserId(0);
                            bdms_fbc_tfpath_f_HK.setPid(0);
                            bdms_fbc_tfpath_f_HK.setReportDept("中国香港");
                            bdms_fbc_tfpath_f_HK.setRealTm(bdms_fbc_tfpath_r.getYmdhm());
                            calendar.setTime(format.parse(bdms_fbc_tfpath_r.getYmdhm()));
                            switch (hourHK) {
                                case 6:
                                    calendar.add(Calendar.HOUR, 6);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_6"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_6"));
                                    break;
                                case 12:
                                    calendar.add(Calendar.HOUR, 12);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_12"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_12"));
                                    break;
                                case 24:
                                    calendar.add(Calendar.HOUR, 24);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_24"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_24"));
                                    break;
                                case 36:
                                    calendar.add(Calendar.HOUR, 36);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_36"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_36"));
                                    break;
                                case 48:
                                    calendar.add(Calendar.HOUR, 48);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_48"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_48"));
                                    break;
                                case 60:
                                    calendar.add(Calendar.HOUR, 60);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_60"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_60"));
                                case 72:
                                    calendar.add(Calendar.HOUR, 72);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_72"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_72"));
                                    break;
                                case 96:
                                    calendar.add(Calendar.HOUR, 96);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_96"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_96"));
                                    break;
                                case 120:
                                    calendar.add(Calendar.HOUR, 120);
                                    bdms_fbc_tfpath_f_HK.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_HK.setJd(jsonObjectData.getDouble("HK_LON_120"));
                                    bdms_fbc_tfpath_f_HK.setWd(jsonObjectData.getDouble("HK_LAT_120"));
                                    break;
                                default:
                                    break;
                            }
                            bdms_fbc_tfpath_fs.add(bdms_fbc_tfpath_f_HK);
                            break;
                        case "JP_":
                            Integer hourJP = Integer.valueOf(key.replaceAll("[^0-9]", ""));
                            BdmsFbcTfpathF bdms_fbc_tfpath_f_JP = new BdmsFbcTfpathF();
                            bdms_fbc_tfpath_f_JP.setTfid(bdms_fbc_tfpath_r.getTfid());
                            bdms_fbc_tfpath_f_JP.setUserId(0);
                            bdms_fbc_tfpath_f_JP.setPid(0);
                            bdms_fbc_tfpath_f_JP.setReportDept("日本");
                            bdms_fbc_tfpath_f_JP.setRealTm(bdms_fbc_tfpath_r.getYmdhm());
                            calendar.setTime(format.parse(bdms_fbc_tfpath_r.getYmdhm()));

                            switch (hourJP) {
                                case 6:
                                    calendar.add(Calendar.HOUR, 6);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_6"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_6"));
                                    break;
                                case 12:
                                    calendar.add(Calendar.HOUR, 12);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_12"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_12"));
                                    break;
                                case 24:
                                    calendar.add(Calendar.HOUR, 24);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_24"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_24"));
                                    break;
                                case 36:
                                    calendar.add(Calendar.HOUR, 36);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_36"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_36"));
                                    break;
                                case 48:
                                    calendar.add(Calendar.HOUR, 48);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_48"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_48"));
                                    break;
                                case 60:
                                    calendar.add(Calendar.HOUR, 60);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_60"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_60"));
                                case 72:
                                    calendar.add(Calendar.HOUR, 72);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_72"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_72"));
                                    break;
                                case 96:
                                    calendar.add(Calendar.HOUR, 96);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_96"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_96"));
                                    break;
                                case 120:
                                    calendar.add(Calendar.HOUR, 120);
                                    bdms_fbc_tfpath_f_JP.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_JP.setJd(jsonObjectData.getDouble("JP_LON_120"));
                                    bdms_fbc_tfpath_f_JP.setWd(jsonObjectData.getDouble("JP_LAT_120"));
                                    break;
                                default:
                                    break;
                            }
                            bdms_fbc_tfpath_fs.add(bdms_fbc_tfpath_f_JP);
                            break;
                        case "USA":
                            Integer hourUSA = Integer.valueOf(key.replaceAll("[^0-9]", ""));
                            BdmsFbcTfpathF bdms_fbc_tfpath_f_USA = new BdmsFbcTfpathF();
                            bdms_fbc_tfpath_f_USA.setTfid(bdms_fbc_tfpath_r.getTfid());
                            bdms_fbc_tfpath_f_USA.setUserId(0);
                            bdms_fbc_tfpath_f_USA.setPid(0);
                            bdms_fbc_tfpath_f_USA.setReportDept("美国");
                            bdms_fbc_tfpath_f_USA.setRealTm(bdms_fbc_tfpath_r.getYmdhm());
                            calendar.setTime(format.parse(bdms_fbc_tfpath_r.getYmdhm()));
                            switch (hourUSA) {
                                case 6:
                                    calendar.add(Calendar.HOUR, 6);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_6"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_6"));
                                    break;
                                case 12:
                                    calendar.add(Calendar.HOUR, 12);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_12"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_12"));
                                    break;
                                case 24:
                                    calendar.add(Calendar.HOUR, 24);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_24"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_24"));
                                    break;
                                case 36:
                                    calendar.add(Calendar.HOUR, 36);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_36"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_36"));
                                    break;
                                case 48:
                                    calendar.add(Calendar.HOUR, 48);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_48"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_48"));
                                    break;
                                case 60:
                                    calendar.add(Calendar.HOUR, 60);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_60"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_60"));
                                case 72:
                                    calendar.add(Calendar.HOUR, 72);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_72"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_72"));
                                    break;
                                case 96:
                                    calendar.add(Calendar.HOUR, 96);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_96"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_96"));
                                    break;
                                case 120:
                                    calendar.add(Calendar.HOUR, 120);
                                    bdms_fbc_tfpath_f_USA.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_USA.setJd(jsonObjectData.getDouble("USA_LON_120"));
                                    bdms_fbc_tfpath_f_USA.setWd(jsonObjectData.getDouble("USA_LAT_120"));
                                    break;
                                default:
                                    break;
                            }
                            bdms_fbc_tfpath_fs.add(bdms_fbc_tfpath_f_USA);
                            break;
                        case "TB_":
                            Integer hourTB = Integer.valueOf(key.replaceAll("[^0-9]", ""));
                            BdmsFbcTfpathF bdms_fbc_tfpath_f_TB = new BdmsFbcTfpathF();
                            bdms_fbc_tfpath_f_TB.setTfid(bdms_fbc_tfpath_r.getTfid());
                            bdms_fbc_tfpath_f_TB.setUserId(0);
                            bdms_fbc_tfpath_f_TB.setPid(0);
                            bdms_fbc_tfpath_f_TB.setReportDept("中国台湾");
                            bdms_fbc_tfpath_f_TB.setRealTm(bdms_fbc_tfpath_r.getYmdhm());
                            calendar.setTime(format.parse(bdms_fbc_tfpath_r.getYmdhm()));

                            switch (hourTB) {
                                case 6:
                                    calendar.add(Calendar.HOUR, 6);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_6"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_6"));
                                    break;
                                case 12:
                                    calendar.add(Calendar.HOUR, 12);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_12"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_12"));
                                    break;
                                case 24:
                                    calendar.add(Calendar.HOUR, 24);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_24"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_24"));
                                    break;
                                case 36:
                                    calendar.add(Calendar.HOUR, 36);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_36"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_36"));
                                    break;
                                case 48:
                                    calendar.add(Calendar.HOUR, 48);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_48"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_48"));
                                    break;
                                case 60:
                                    calendar.add(Calendar.HOUR, 60);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_60"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_60"));
                                case 72:
                                    calendar.add(Calendar.HOUR, 72);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_72"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_72"));
                                    break;
                                case 96:
                                    calendar.add(Calendar.HOUR, 96);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_96"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_96"));
                                    break;
                                case 120:
                                    calendar.add(Calendar.HOUR, 120);
                                    bdms_fbc_tfpath_f_TB.setReportTm(format.format(calendar.getTime()));
                                    bdms_fbc_tfpath_f_TB.setJd(jsonObjectData.getDouble("TB_LON_120"));
                                    bdms_fbc_tfpath_f_TB.setWd(jsonObjectData.getDouble("TB_LAT_120"));
                                    break;
                                default:
                                    break;
                            }
                            bdms_fbc_tfpath_fs.add(bdms_fbc_tfpath_f_TB);
                            break;
                        default:
                            // 处理其他部门的逻辑
                            break;
                    }
                }

                bdms_fbc_tfpath_fs.sort(Comparator.comparing(BdmsFbcTfpathF::getRealTm).thenComparing(BdmsFbcTfpathF::getReportTm));
                List<BdmsFbcTfpathF> bdms_fbc_tfpath_fList =  bdms_fbc_tfpath_fs.stream()
                        .filter(data -> data.getJd() != null && data.getWd() != null)
                        .collect(Collectors.toList());
                for (BdmsFbcTfpathF bdms_fbc_tfpath_f : bdms_fbc_tfpath_fList) {
                    System.out.println("预报："+bdms_fbc_tfpath_f);
                }


                if (bdms_fbc_tfpath_fList.size()>0){
                    //数据入库
                    bdmsFbcTfpathFService.insertAll(bdms_fbc_tfpath_fList);
                }

           }

        }

        //基础入库
        int res =bdmsFbcTfService.insertBatch(bdmsFbcTfs);
        System.out.println("基础信息条数:"+res);
        //实测入库
        System.out.println("实测信息条数:"+bdmsFbcTfpathRService.insertBatch(bdmsFbcTfpathRS));
      return res;
    }

}
